<?php

namespace App\Console\Commands;


use App\Facades\Node;
use App\Models\BpmMaindata;
use Illuminate\Console\Command;
use Mtownsend\XmlToArray\XmlToArray;
use App\Services\NodeService;

class TestItService extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'test:it';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $service = new NodeService();
        $request  = [
            'leadTeam' => '844',
            'newProductText0_show' => '',
            'project_class_show' => '',
            'involveDocke' => '是',
            'decomposePerson1' => '',
            'text21_show' => '',
            'ggtopl' => '',
            'project_type' => '',
            'person_choess' => '',
            'projectLeader' => ''
        ];

        $params = [
            'docUnid' => 'e301128906817047a708f8e0a8ca74ba99da',
            'nextNodeid' => 'T10015,T10340',
            'remark' => '同意'
        ];

        Node::nodeHandle($request,$params);

        $xml = BpmMaindata::where('WF_OrUnid','db8ed76804e66046c209c5b08f6f2edcac22')
            ->value('XmlData');

        $array = XmlToArray::convert($xml);

        $result = [];

        foreach ($array['WFItem'] as $value){
            if (isset($value['@attributes']['name']) && !empty($value['@attributes']['name'])) {
                $result[$value['@attributes']['name']] = $value['@content'] ?? null;
            }
        }

        $string = '<![CDATA[<Items>';

        foreach ($result as $key => $value) {
            if (empty($value)) {
                $string .= "<WFItem name=\"".$key."\"></WFItem>";
            } else{
                $string .= "<WFItem name='".$key."'>".$value."</WFItem>";
            }
        }


//        <!--Optional:-->
//         <actionid>EndUserTask</actionid>
//         <!--Optional:-->
//         <processid>81df916c0da0a040950812d0de4b80dbd575</processid>
//         <!--Optional:-->
//         <docUnid>d82ce3b90d99004eff0af3602a477c8478aa</docUnid>
//         <!--Optional:-->
//         <nextNodeid>T10015,T10340</nextNodeid>
//         <!--Optional:-->
//<!--         <nextUserList></nextUserList>-->
//         <!--Optional:-->
//         <userid>30000775</userid>
//         <!--Optional:-->
//         <remark>同意</remark>
//         <!--Optional:-->
//         <sysid>pms</sysid>
//         <!--Optional:-->
//         <syspwd>pms</syspwd>


    $string .= "</Items>]]>";

        $url = "http://192.168.1.194:8080/bpm/WF_RunProcessPort?wsdl";

        $soapService = new \SoapClient($url);

        $result = $soapService->WF_RunProcessPort($string,[
            'params'            => json_encode([
                'actionid' => 'EndUserTask',
                'processid' => '81df916c0da0a040950812d0de4b80dbd575',
                'docUnid'  => 'db8ed76804e66046c209c5b08f6f2edcac22',
                'nextNodeid' => 'T10015,T10340',
                'userid' => '30000775',
                'remark' => '同意',
                'sysid'  => 'pms',
                'syspwd' => 'pms'
            ])
        ]);

        dd($result);

    }
}
